package com.rovinj_server.adapter;

import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.rovinj_server.R;
import com.rovinj_server.entity.People;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by root on 8/13/16.
 */
public class PeopleRecyclerAdapter extends RecyclerView.Adapter<PeopleRecyclerAdapter.PeopleHolder>{
    private List<People> peoples;

    public PeopleRecyclerAdapter() {
        peoples = new ArrayList<>();
    }

    public PeopleRecyclerAdapter(List<People> peoples) {
        this.peoples = peoples;
    }

    public void add(People people){
        peoples.add(people);
    }

    public List<People> getPeoples(){
        return peoples;
    }

    @Override
    public PeopleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item, parent, false);
        return new PeopleHolder(v);
    }

    @Override
    public void onBindViewHolder(PeopleHolder holder, int position) {
        People people = peoples.get(position);
        holder.location.setText(people.getLocation());
        holder.barode.setText(people.getBarode());
        holder.code.setText(people.getCode());
        holder.sjnumber.setText(people.getSjnumber());


        holder.lessThan.setText(people.getLessThan());
        holder.moreThan.setText(people.getMoreThan());
        holder.discNum.setText(people.getDiscNum());

        holder.sjnumberZong.setText(people.getSjnumberZong());
        holder.moreThanZong.setText(people.getMoreThanZong());
        holder.lessThanZong.setText(people.getLessThanZong());
        holder.discNumberZong.setText(people.getDiscNumberZong());
    }

    @Override
    public int getItemCount() {
        return peoples.size();
    }

    static class PeopleHolder extends RecyclerView.ViewHolder{
        AppCompatTextView location, barode, discNum, lessThan, moreThan,code,sjnumber,sjnumberZong,moreThanZong,lessThanZong,discNumberZong;

        public PeopleHolder(View itemView) {
            super(itemView);
            location = (AppCompatTextView) itemView.findViewById(R.id.textview_name);
            barode = (AppCompatTextView) itemView.findViewById(R.id.textview_job);
            discNum = (AppCompatTextView) itemView.findViewById(R.id.textview_phone);
            lessThan = (AppCompatTextView) itemView.findViewById(R.id.textview_email);
            moreThan = (AppCompatTextView) itemView.findViewById(R.id.textview_address);
            code = (AppCompatTextView) itemView.findViewById(R.id.textview_6);
            sjnumber = (AppCompatTextView) itemView.findViewById(R.id.textview_7);
            sjnumberZong = (AppCompatTextView) itemView.findViewById(R.id.textview_8);
            moreThanZong = (AppCompatTextView) itemView.findViewById(R.id.textview_9);
            lessThanZong = (AppCompatTextView) itemView.findViewById(R.id.textview_10);
            discNumberZong = (AppCompatTextView) itemView.findViewById(R.id.textview_11);

        }
    }
}
